**
**  This file corresponds to the paper:
**
**  Aidt, Toke, Zareh Asatryan, Lusine Badalyan and Friedrich Heinemann. 2018.
**        Vote Buying or (Political) Business (Cycles) as Usual?
**        The Review of Economics and Statistics, forthcoming.
**
**  This DO file replicates the third (micro-macro) part of the analysis, see Online Appendix D (Reconciling micro and macro evidence)
**  For the DO files replicating the first(macro) and second(micro) parts of the analysis, see do_votebuying_macro and do_votebuying_micro.
**
**  Date: 07 Dec 2018
**       

clear all
set more off, perm
cd "C:\Users\user\Desktop\Vote Buying\0_RESTAT"
* if not already ssc install the following programs: xtivreg2 outreg2 tabout xtabond2 egenmore coefplot

** Load data (daily M1 data from Armenia, 1995:m12-2018:m8, source: CBA)
use m1_daily_arm.dta, clear

format date %td
gen year  = year(date)
gen month = month(date)
gen week  = week(date)
gen day   = day(date)

** Define election dates
* 10 national elections in 1995:m12-2018:m8; total available sample, and
* 6  national elections in 2001:m1-2016:m12; sample HH-surveys available
gen     el_day=0
replace el_day=1 if date==13415 | date==13955 | date==14395 | date==15756 | date==15851 | date==17300 | date==17581 | date==19120 | date==19408 | date==20912

label var el_day "Election date"
local eldays         15756 15851 17300 17581 19120 19408
local eldays_control 15756 15851 17300 17581 19120 19408   15391 15486 16216 16216 16935 17946 18755 19773


** Regressions around election months as in Macro-analysis

* Define election months
sort date
gen f0 = el_day
gen f1 = el_day[_n-30]
gen l1 = el_day[_n+61]
foreach i in f0 f1 l1{
bysort year month: egen el_month_`i'=mean(`i')
replace el_month_`i' =1 if el_month_`i'>0 & el_month_`i'!=.
label var el_month_`i' "Election calendar month"
drop `i'
}

* Table D.1: columns 1-3
foreach i in f0 l1 f1{
reg m1 el_month_`i' i.day i.week i.month i.year
est store m`i'
}


** Regressions around election days as in Micro-analysis

* Restrict data to micro sample (HH-surveys available only for these years)
keep if year>=2001 & year<=2016

* Define Treatment (12 day before and 8 day after) and Control (80 or 40 day)
sort date
gen treat=0
foreach i in `eldays'{
replace treat = 1 if date>=`i'-12 & date<=`i'+8
label var treat "Treatment (-12, +8) days around election; else 0"
}
gen control1=0
gen control2=0
foreach i in `eldays_control'{
replace control1 = 1 if date>=`i'-66 & date<=`i'+14
replace control2 = 1 if date>=`i'-26 & date<=`i'+14
}

* Table D.1: columns 4-6
reg m1 treat i.day i.week i.month i.year
est store b1
reg m1 treat i.day i.week i.month i.year if control1==1
est store c1
reg m1 treat i.day i.week i.month i.year if control2==1
est store c2

outreg2  [mf0 ml1 mf1 b1 c1 c2] using arm_micro_macro, label e(F) ctitle() tex(frag) dec(4) excel drop() sortvar(el_month_f0 el_month_l1 el_month_f1 treat) append

clear
exit
